package com.spark.concurrency.thread.method;

public class NotifyTest {
    final static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {


        //lock.wait();
        //lock.notify();// lock.notifyAll();
        //线程休眠
        // 休眠 1 秒
        Thread.sleep(1000);
        //等待线程执行完成

        Thread joinThread = new Thread(() -> {
            try {
                synchronized (lock) {
                    System.out.println("走一个");
                    Thread.sleep(1000);
                    System.out.println("等……");
                    lock.wait();
                    System.out.println("出来了……");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        joinThread.start();
        new Thread(() -> {
            synchronized (lock) {
                System.out.println("放");
                lock.notify();
            }
        }).start();
        joinThread.join();

        System.out.println("主程序");
    }
}
